/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ticketmaster.dao;

import ticketmaster.dataobject.SeatCategory;
import javax.sql.*;
import java.sql.*;
import java.util.*;
import java.util.logging.*;

/**
 *
 * @author Xiaolong Xue
 */
public class SeatCategoryDAO extends BaseEntityDAO
{
    public SeatCategoryDAO()
    {
        //construct a SeatCategoryDAO object
    }

    /**
     * Insert a new SeatCategory object into database
     * @param seatCategory the new seatCategory entity to be inserted
     * @return newly created SeatCategor ID, or  0 when error
     */
    public int insertSeatCategory(SeatCategory seatCategory)
    {
        return save(seatCategory);
    }

    /**
     * Delete a SeatCategory object that matches the supplied criteria
     * @param seatCategory the supplied criteria
     * @return true if success, or false
     */
    public boolean deleteSeatCategory(SeatCategory seatCategory)
    {
        return delete(seatCategory);
    }

    /**
     * Update the seatCategory by using data from the SeatCategory Data Object(from UI)
     * @param seatCategory the seatCategory Data Object to be updated
     * @return true on success, false on failure or error
     */
    public boolean updateSeatCategory(SeatCategory seatCategory)
    {
        if(seatCategory.getSeatCategoryID() == 0)
            return false;
        if(update(seatCategory))
            return true;
        else
            return false;
    }

    /**
     * Get the seatCategory that matches the supplied criteria
     * @param seatCategory the supplied criteria
     * @return a SeatCategory Object if found, or null on error or if not found
     */
    public SeatCategory findSeatCategory(SeatCategory seatCategory)
    {
        String sql = null;
        if(seatCategory.getSeatCategoryID() == 0)
            return null;
        else
            sql = buildQuerySQL(seatCategory);
        RowSet srs = query(sql);
        try
        {
            srs.next();
        }
        catch(SQLException ex)
        {
            Logger.getLogger(SeatCategoryDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return (SeatCategory) this.getObject(srs, seatCategory);
    }

    /**
     * Get all seatCategory that match the supplied criteria
     * @param seatCategory supplied criteria
     * @return a RowSet of seatCategory
     */
    public RowSet getSeatCategoryRowSet(SeatCategory seatCategory)
    {
        String sql = buildQuerySQL(seatCategory);
        return query(sql);
    }

    /**
     * Get all seatcategory that match the supplied criteria
     * @param seatCategory supplied criteria
     * @return a collection of SeatCategory Data Objects
     */
    public Collection<SeatCategory> getSeatCategoryDO(SeatCategory seatCategory)
    {
        String sql = buildQuerySQL(seatCategory);
        RowSet srs = query(sql);
        Collection<SeatCategory> seatCategories = new ArrayList<SeatCategory>();
        try
        {
            while(srs.next())
            {
                SeatCategory seatCategoryDO = (SeatCategory) this.getObject(srs, seatCategory);
                seatCategories.add(seatCategoryDO);
            }
        }
        catch(SQLException ex)
        {
            Logger.getLogger(SeatCategoryDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return seatCategories;
    }
}
